#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>
#include <sstream>
#include <list>
#include <stack>
using namespace std;


struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};
 
class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int n = nums.size();
        int i = 0 ,j = n-1,cnt=0;
        if(n<1)return 0;
        while(i<=j) {
            if(nums[i] == val ){
                nums[i] = nums[j--];
            }else i++;
        }
        cout<<"[";
        for(int k = 0;k<i;k++)cout << nums[k] << " ";
        cout<<"]"<<endl;
        return i;          
    }
};


int main(){

    vector < vector<int> > ans;
    Solution sp;
    vector<int> nums = {0,1,2,2,3,0,4,2};
    int val = 2;
    string s = "){";
    
    cout<<  sp.removeElement(nums,val) <<endl;
    return 0;
}